<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">

			<el-row >
				<el-col span="10" >
					<el-form-item label="姓名" prop="customerName">
						<el-input v-model="form.customerName"></el-input>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="性别" prop="customerGender" label-width="140px">
						<el-select v-model="form.customerGender" placeholder="请选择..">
							<el-option v-for="item in options" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="年龄" prop="customerAge">
						<el-input v-model="form.customerAge"></el-input>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="健康管家" prop="healthPerson" label-width="140px">
						<el-input v-model="form.healthPerson"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="健康卡号/身份证号" prop="idNumber" label-width="140px">
						<el-input v-model="form.idNumber"></el-input>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="档案编号" prop="recordId" label-width="140px">
						<el-input v-model="form.recordId"></el-input>
					</el-form-item>
				</el-col>
			</el-row>


			<el-row>
				<el-col span="10">
					<el-form-item label="评估医生" prop="assessDoctor">
						<el-input v-model="form.assessDoctor"></el-input>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="责任医生" prop="respDoctor" label-width="140px">
						<el-input v-model="form.respDoctor"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="楼房" prop="house">
						<el-input v-model="form.house"></el-input>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="床号" label-width="140px">
						<el-input v-model="form.bedId"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="入住时间" prop="checkinDate">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.checkinDate"
							placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="合同到期时间" prop="endDate" label-width="140px">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.endDate" placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="身体状况简述" label-width="140px">
						<el-input v-model="form.bodyInfo"></el-input>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="护理等级" prop="nurseLevelName" label-width="140px">
						<el-input v-model="form.nurseLevelName"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="紧急联系人" prop="urgentContact" label-width="100px">
						<el-input v-model="form.urgentContact"></el-input>
					</el-form-item>
				</el-col>

				<el-col span="10">
					<el-form-item label="联系人电话" prop="contactTelephone" label-width="140px">
						<el-input v-model="form.contactTelephone"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col>
					<el-form-item label="评估结果">
						<el-input v-model="form.results"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row></el-row>
			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>


		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'ClientinformationAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					customerName: '',
					customerGender: '',
					customerAge: '',
					idNumber: '',
					recordId: '',
					assessDoctor: '',
					respDoctor: '',
					healthPerson: '',
					house: '',
					bedId: '',
					checkinDate: '',
					endDate: '',
					bodyInfo: '',
					nurseLevelName: '',
					urgentContact: '',
					contactTelephone: '',
					results: ''
				},
				rules: {
					customerName: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					customerGender: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					customerAge: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					idNumber: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					recordId: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					assessDoctor: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					respDoctor: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					healthPerson: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					house: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					bedId: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					checkinDate: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					endDate: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					nurseLevelName: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					urgentContact: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					contactTelephone: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}]
				},
				isupdate: false,
				options: [{
					value: '男',
					label: '男'
				}, {
					value: '女',
					label: '女'
				}]
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/customer/getById',
					response => {
						this.form.customerId = this.editid;
						this.form.customerName = response.obj.customerName;
						this.form.customerGender = response.obj.customerGender;
						this.form.customerAge = response.obj.customerAge;
						this.form.idNumber = response.obj.idNumber;
						this.form.recordId = response.obj.recordId;
						this.form.assessDoctor = response.obj.assessDoctor;
						this.form.respDoctor = response.obj.respDoctor;
						this.form.healthPerson = response.obj.healthPerson;
						this.form.house = response.obj.house;
						this.form.bedId = response.obj.bedId;
						this.form.checkinDate = response.obj.checkinDate;
						this.form.endDate = response.obj.endDate;
						this.form.bodyInfo = response.obj.bodyInfo;
						this.form.nurseLevelName = response.obj.nurseLevelName;
						this.form.urgentContact = response.obj.urgentContact;
						this.form.contactTelephone = response.obj.contactTelephone;
						this.form.results = response.obj.results;
					}, {
						customerId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				if (this.editid) {
					axios.post(
						'/customer/update',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				} else {
					axios.post(
						'/customer/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				}

			}
		}
	};
</script>

<style scoped>
	.el-row{
		height: 60px;
	}
</style>
